#include "widget.h"
#include "ui_widget.h"
#include <QPainter>
#include <QIcon>
#include <QPushButton>
#include "gameselect.h"
#include <QSound>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setFixedSize(1000, 900);
    this->setWindowIcon(QIcon(":/res/icon.jpg"));
    this->setWindowTitle("贪吃蛇游戏");

    //开始游戏
    QPushButton* startButton = new QPushButton(this);
    QFont font("华文行楷", 30);
    startButton->setFont(font);
    startButton->move(420, 600);
    startButton->setText("开始游戏");
    QString style("QPushButton{border : 5px solid #ee0000; border-radius : 30px; color : #33ffcc;} "
                  "QPushButton:hover{border : 5px solid #33ffcc; color : #ee0000;}");
    startButton->setStyleSheet(style);

    GameSelect* gameselect = new GameSelect;
    connect(startButton, &QPushButton::clicked, [=](){
        this->close();
        gameselect->setGeometry(this->geometry());
        gameselect->show();
    });
    connect(startButton, &QPushButton::pressed, [=](){
        QSound::play(":/res/start.wav");
    });

    //退出游戏
    QPushButton* exitButton = new QPushButton(this);
    exitButton->move(420, 700);
    exitButton->setFont(font);
    exitButton->setStyleSheet(style);
    exitButton->setText("退出游戏");
    connect(exitButton, &QPushButton::clicked, [=](){
        this->close();
    });
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *event)
{
    (void)event;
    QPainter painter(this);
    QPixmap pixmap(":/res/game_hall.jpg");
    painter.drawPixmap(0, 0, this->width(), this->height(), pixmap);
}

